
# from celery_tasks.main import app

from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest
# @app.task
def send_code(mobile, code):
    client = AcsClient('LTAI5tN4bpEoxJRmdThQnMjN', 'Ky7SI4LUm1QhAG7eTnQl6CQjMSIF2o', 'cn-hangzhou')

    request = CommonRequest()
    request.set_accept_format('json')
    request.set_domain('dysmsapi.aliyuncs.com')
    request.set_method('POST')
    request.set_protocol_type('https')
    request.set_version('2017-05-25')
    request.set_action_name('SendSms')

    request.add_query_param('RegionId', "cn-hangzhou")
    request.add_query_param('PhoneNumbers', mobile)
    request.add_query_param('SignName', "阿里云短信测试")
    request.add_query_param('TemplateCode', "SMS_154950909")
    request.add_query_param('TemplateParam', "{\"code\":\"%s\"}" % code)

    response = client.do_action(request)
    print(str(response, encoding='utf-8'))

















